/**
 * Created by Saxon Cheng on 2017/3/16.
 */
'use strict';
import React,{Component,PropTypes} from 'react';
import {
    TouchableOpacity,
    View,
    Text
} from 'react-native';

import * as PayConfig from '../constants/PayConfig';
import * as Actions from "../actions/PayAction"
import {connect} from "react-redux"

class PayDemo extends Component{

    constructor(props){
        super(props);
    }
    render(){
        console.log(this.props.paySuccess+"---"+this.props.errMsg);
        return(
            <View style={{flex:1,alignItems:'center',justifyContent:'center'}}>

                {this.props.paySuccess ? <Text style={{marginTop:30}}>{this.props.pkId}----{this.props.price}</Text>
                    : <Text style={{marginTop:20}}>{this.props.errMsg}</Text>}


                <TouchableOpacity onPress={this.onCreateProduct.bind(this,PayConfig.ALIPAY)} style={{marginTop:30}}>
                    <Text>支付宝支付</Text>
                </TouchableOpacity>
                <TouchableOpacity onPress={this.onCreateProduct.bind(this,PayConfig.WXPAY)} style={{marginTop:30}}>
                    <Text>微信支付</Text>
                </TouchableOpacity>


            </View>
        )
    }

    onCreateProduct(payType){
        var workId = "123456";
        var workType = "123456";
        var userId = "123456";
        var payType = payType;
        this.props.dispatch(Actions.fetchProductStart(workId,workType,userId,payType))
    }
}

function mapStateToProps(store) {

    const {payReducer} = store;

    return {
        isPaying:payReducer.isPaying,
        pkId:payReducer.pkId,
        price:payReducer.price,
        paySuccess:payReducer.paySuccess,
        errMsg:payReducer.errMsg
    };
}
export default connect(mapStateToProps)(PayDemo);